package com.egoo.ticket.server.controller;


import com.egoo.ticket.server.pojo.dto.WorkOrderRelationDto;
import com.egoo.ticket.server.service.WorkOrderRelationService;
import com.egoo.ticket.server.utils.common.DbResponse;
import com.egoo.ticket.server.utils.common.ResponseConstant;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author donny
 * @since 2020-04-23
 */
@Slf4j
@RestController
@RequestMapping(value = "/v1/workOrderRelation",produces = "application/json")
@Api(value = "工单关联关系管理",tags = "工单关联关系管理",description = "工单关联关系管理")
public class WorkOrderRelationController {

	@Autowired
	private WorkOrderRelationService workOrderRelationService;

	@ApiOperation(value = "处理抄送人",notes = "处理抄送人")
	@RequestMapping(method = RequestMethod.POST,value = "/handleSender")
	public DbResponse handleSender(@RequestBody WorkOrderRelationDto workOrderRelationDto){
		if (StringUtils.isEmpty(workOrderRelationDto.getWorkOrderId())){
			return new DbResponse(ResponseConstant.RES_FAIL_CODE,"工单id不能为空！");
		}
		if (StringUtils.isEmpty(workOrderRelationDto.getSender())){
			return new DbResponse(ResponseConstant.RES_FAIL_CODE,"抄送人id不能为空！");
		}
		workOrderRelationService.updateWorkOrderRelation(workOrderRelationDto);
		return new DbResponse(ResponseConstant.RES_SUCCESS_CODE,
				ResponseConstant.UPDATE_SUCCESS_MSG);
	}

	@ApiOperation(value = "关联工单(不新建)",notes = "关联工单(不新建)")
	@RequestMapping(method = RequestMethod.POST,value = "/concatWorkOrder")
	public DbResponse concatWorkOrder(@RequestBody WorkOrderRelationDto workOrderRelationDto){
		if (StringUtils.isEmpty(workOrderRelationDto.getCurrentWorkOrderId())){
			return new DbResponse(ResponseConstant.RES_FAIL_CODE,"当前工单id不能为空！");
		}
		if (StringUtils.isEmpty(workOrderRelationDto.getConcatWorkOrderIds())){
			return new DbResponse(ResponseConstant.RES_FAIL_CODE,"关联人id不能为空！");
		}
		return workOrderRelationService.concatWorkOrder(workOrderRelationDto);

	}
}
